// import { turn } from 'core-js/core/array';
import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/PC/Navigation.vue";
import Vuex from 'vuex' 
Vue.use(VueRouter);

const routes = [
  // 后台管理
  {
    // 管理登录
    path: "/manage/login",
    name: "/manage/login",
    component: () => import("../views/PC/user/Login.vue"),
    meta: {
      hideHeader: true, // 隐藏头
    },
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    // 二级路由
    children: [
      {
        path: "index",
        name: "/home/index",
        // 懒加载
        component: () => import("../views/PC/index.vue"),
        meta: {
          // breadcrumbs: ["首页"],
          hideHeader: true, // 隐藏头
        },
      },
      {
        path: "approve-unexamine",
        name: "/home/approve-unexamine",
        component: () => import("../views/PC/approve/unexamine.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["审批店铺申请管理", "未审批店铺申请"],
        },
      },
      {
        path: "approve-inexamine",
        name: "/home/approve-inexamine",
        component: () => import("../views/PC/approve/inexamine.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["审批店铺申请管理", "已审批店铺申请"],
        },
      },
      {
        path: "shop-list",
        name: "/home/shop-list",
        component: () => import("../views/PC/store/storeList.vue"),
        // meta称为路由对象的元数据，在此处可以自定义配置一些路由相关参数
        // 方便在组件使用
        meta: {
          // 在此自定义一个meta数据，保存当前路由应显示的面包屑导航列表
          hideHeader: true, // 隐藏头
          breadcrumbs: ["店铺管理", "店铺列表"],
        },
      },
      {
        path: "shop-add",
        name: "/home/shop-add",
        component: () => import("../views/PC/store/storeAdd.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["店铺管理", "店铺添加"],
        },
      },
      {
        path: "shop-details/:id",
        name: "/home/shop-details",
        component: () => import("../views/PC/store/storeDetails.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          // breadcrumbs: {"店铺管理":null ,'店铺列表':'/home/shop-list','店铺详情':null},
        },
      },
      {
        path: "shopRevise/:id",
        name: "/home/shopRevise",
        component: () => import("../views/PC/store/storeRevise.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["店铺管理", "店铺修改信息"],
        },
      },
      {
        path: "shop-revise",
        name: "/home/shop-revise",
        component: () => import("../views/PC/store/storeRevise.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["店铺管理", "店铺修改信息"],
        },
      },
      {
        path: "pro-list",
        name: "/home/pro-list",
        component: () => import("../views/PC/pro/proList.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["商品管理", "商品列表"],
        },
      },
      {
        path: "pro-add",
        name: "/home/pro-add",
        component: () => import("../views/PC/pro/proAdd.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["商品管理", "商品添加"],
        },
      },
      {
        path: "pro-revise/:id",
        name: "/home/pro-revise",
        component: () => import("../views/PC/pro/proRevise.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["商品管理", "商品修改信息"],
        },
      },
      {
        path: "pro-details/:id",
        name: "/home/pro-details",
        component: () => import("../views/PC/pro/proDetails.vue"),
        meta: {
          hideHeader: true, // 隐藏头
        },
      },
      {
        path: "user-list",
        name: "/home/user-list",
        component: () => import("../views/PC/user/userList.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["用户管理", "用户列表"],
        },
      },
      {
        path: "user-details/:id",
        name: "/home/user-details",
        component: () => import("../views/PC/user/userDetails.vue"),
        meta: {
          hideHeader: true, // 隐藏头
        },
      },
      {
        path: "user-revise/:id",
        name: "/home/user-revise",
        component: () => import("../views/PC/user/userRevise.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["用户管理", "用户修改信息"],
        },
      },
      {
        path: "user-add",
        name: "/home/user-add",
        component: () => import("../views/PC/user/userAdd.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["用户管理", "用户添加"],
        },
      },
      {
        path: "un-Reserva",
        name: "/home/un-Reserva",
        component: () => import("../views/PC/reservation/unReserva.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["预约管理", "未完成预约"],
        },
      },
      {
        path: "reserva",
        name: "/home/reserva",
        component: () => import("../views/PC/reservation/reservat.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["预约管理"],
        },
      },
      {
        path: "in-Reserva",
        name: "/home/in-Reserva",
        component: () => import("../views/PC/reservation/inReserva.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["预约管理", "已完成预约"],
        },
      },
      {
        path: "expire-Reserva",
        name: "/home/expire-Reserva",
        component: () => import("../views/PC/reservation/expireReserva.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["预约管理", "失效预约"],
        },
      },
      {
        path: "complaint",
        name: "/home/complaint",
        component: () => import("../views/PC/complaint/storeComplaint.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["投诉警告管理"],
        },
      },
      {
        path: "complaint-user",
        name: "/home/complaint-user",
        component: () => import("../views/PC/complaint/complaintUserList.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["投诉管理","投诉 - 用户因素"],
        },
      },
      {
        path: "Complaint-store",
        name: "/home/Complaint-store",
        component: () => import("../views/PC/complaint/complaintStoreList.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["投诉管理","投诉 - 店铺因素"],
        },
      },
      {
        path: "un-Complaint",
        name: "/home/un-Complaint",
        component: () => import("../views/PC/complaint/unComplaintList.vue"),
        meta: {
          hideHeader: true, // 隐藏头
          breadcrumbs: ["投诉管理",'未处理投诉'],
        },
      },
      // {
      //   path: "advertising",
      //   name: "/home/advertising",
      //   component: () => import("../views/PC/advertising"),
      //   meta: {
      //     hideHeader: true, // 隐藏头
      //     breadcrumbs: ["广告宣传管理"],
      //   },
      // },
      {
        path: "unProcess",
        name: "/home/unProcess",
        component: () => import("../views/PC/process/unProcess.vue"),
        meta: {
          breadcrumbs: ["审核管理","未审核列表"],
        },
      },
      {
        // 匹配： /home/showingon-plan-list/3
        path: "inProcess",
        name: "/home/inProcess",
        component: () => import("../views/PC/process/inProcess.vue"),
        meta: {
          breadcrumbs:["审核管理","已审核列表"],
        },
      },
    ],
  },
  //用户投诉
  {
    path: "/complaint",
    name: "complaint",
    component: () => import("../views/PE/my/Complaint.vue"),
  },
  //商家注入
  {
    path: "/upload",
    name: "Upload",
    component: () => import("../views/PE/commodity/AddMy.vue"),
  },
  //客服咨询
  {
    path: "/consultservice",
    name: "ConsultService.",
    meta: {
      hideHeader: true, // 隐藏头
    },
    component: () => import("../views/PE/my/ConsultService.vue"),
  },
  //错误界面
  {
    path: "*",
    name: "ErroeView",
    component: () => import("../views/NotFond.vue"),
  },
  // 定位
  {
    path: "/location",
    name: "LocationView",
    component: () => import("../views/PE/my/LocationView.vue"),
  },
  //摄影展示
  {
    path: "/syzs",
    name: "摄影展示",
    component: () => import("../views/PE/pro/SheYingZhanShi.vue"),
  },
  //预约
  {
    path: "/sc",
    name: "预约",
    component: () => import("../views/PE/my/ConsultingService.vue"),
  },
  {
    path: "/means",
    name: "我的主页",
    meta: {
      hideHeader: true, // 隐藏头
    },
    component: () => import("../views/PE/my/MyHomePage.vue"),
  },
  {
    path: "/information",
    name: "个人资料",
    meta: {
      hideHeader: true, // 隐藏头
    },
    component: () => import("../views/PE/my/Address.vue"),
  },
  // 预约单
  {
    path: "/reservation",
    name: "reservation",
    component: () => import("../views/PE/my/Reservation.vue"),
  },
  // 心愿单
  {
    path: "/wish",
    name: "Wish",
    component: () => import("../views/PE/my/WishView.vue"),
  },
  // 注册
  {
    path: "/register",
    name: "Register",
    meta: {
      hideHeader: true, // 隐藏头
    },
    component: () => import("../views/PE/my/RegisterView.vue"),
  },
  // 用户登录
  {
    path: "/login",
    name: "Login",
    meta: {
      hideHeader: true, // 隐藏头
    },
    component: () => import("../views/PE/my/LoginView.vue"),
  },
  {
    path: "/personality",
    name: "personality",
    component: () => import("../views/PE/pro/Personality.vue"),
  },
  {
    path: "/chinese",
    name: "chinese",
    component: () => import("../views/PE/pro/ChineseStyle.vue"),
  },
  {
    path: "/western",
    name: "western",
    component: () => import("../views/PE/pro/WesternStyle.vue"),
  },
  // 商品详细
  {
    path: "/westerndetail",
    name: "WesternDetail",
    component: () => import("../views/PE/pro/WesternDetail.vue"),
  },
  {
    path: "/",
    name: "主页",
    component: () => import("../views/PE/indedxn.vue"),
  },

];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// 解决重复跳转报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

// router.beforeEach((to, from, next) => {
//   // 路由跳转后，让页面回到顶部
//   // chrome
//   document.body.scrollTop = 0; // firefox
//   document.documentElement.scrollTop = 0; // safari
//   window.pageYOffset = 0; // 调用 next()，一定要调用 next 方法，否则钩子就不会被销毁
//   next();
//   //to 即将进入的路由
//   //from 即将离开的路由
//   //next 放行
// // console.log(from); // 起点路由对象
// // console.log(to); // 目标路由对象
// });
// 白名单
const list = ['']
// 注册全局的前置路由守卫，监控路由的跳转过程：当从A跳转到B之前执行
router.beforeEach((to, from, next) => {
  // 判断当前是否跳转到登录页
  if (to.path == "/manage/login" || !to.path.includes('home') ) {
    // 路由跳转后，让页面回到顶部
    // console.log('333');
    document.body.scrollTop = 0; // firefox
    document.documentElement.scrollTop = 0; // safari
    window.pageYOffset = 0; 
    // 不拦截去往登录页面
    next();
  } else {
    // 判断用户是否已经登录，只有登录过的用户，才可以跳转到其他页面
    if ( window.sessionStorage.getItem('uid') !== null ) {
        // 路由跳转后，让页面回到顶部
      document.body.scrollTop = 0; // firefox
      document.documentElement.scrollTop = 0; // safari
      window.pageYOffset = 0; 
      // console.log('111');
      next();
    } else {
      // 否则，未登录直接跳转到登录页面
      // console.log('222');
      next("/manage/login");
    }
  }
});
export default router;
